package com.followme.module.common;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * User: Kamil.O
 * Description: Common class for common module
 * Date: 24.11.13
 * Time: 15:29
 */
public class CommonModuleUtil extends Activity{
    public static final String TAG_LOG_CAT = "MODULE_COMMON";

    public static void showDialogAlert(final Context mContext,
                                       String title,
                                       String message,
                                       String banAccept,
                                       String btnCancel,
                                       final String redirectAction){

        AlertDialog.Builder alertDialog = new AlertDialog.Builder(mContext);
        alertDialog.setTitle(title);
        alertDialog.setMessage(message);

        alertDialog.setPositiveButton(banAccept, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int which) {
                Intent intent = new Intent(redirectAction);
                mContext.startActivity(intent);
            }
        });

        alertDialog.setNegativeButton(btnCancel, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });

        alertDialog.show();
    }


    public static Date getDateFromString(String format,String dateToConvert){
        SimpleDateFormat simpleDateFormat =
                new SimpleDateFormat(format, Locale.getDefault());

        try {
            return simpleDateFormat.parse(dateToConvert);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        return null;
    }
}
